package com.bw.home.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import androidx.annotation.Nullable;

import com.bw.home.R;
import com.bw.home.databinding.WidgetTitlebarBinding;

/**
 * @author:created by hahajing
 * 时间：2024/4/26 0026
 * 企鹅号:444511958
 * 描述:
 */
public class TitleBar extends LinearLayout {

    private OnClickListener onClickListener;

    public void setOnClickListener(OnClickListener onClickListener) {
        this.onClickListener = onClickListener;
    }

    public TitleBar(Context context) {
        super(context);
        initView(context);
    }

    public TitleBar(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initView(context);
    }

    public TitleBar(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
    }

    private void initView(Context context) {
        this.removeAllViews();

        View view = LayoutInflater.from(context).inflate(R.layout.widget_titlebar,null,false);
        ViewGroup.LayoutParams params=new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        view.setLayoutParams(params);
        WidgetTitlebarBinding binding = WidgetTitlebarBinding.bind(view);
        binding.tvHomeWidgetTitlebar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onClickListener!=null){
                    onClickListener.onClick(v);
                }
            }
        });
        this.addView(view);
    }

    public interface OnClickListener{
        void onClick(View view);
    }

}
